<template>
  <div>
    <el-dialog title="提示" :visible.sync="dialogVisibleEditInvite" width="30%">
      <div>
        <el-form ref="formAdd" :model="editForm" label-width="80px">
          <el-form-item label="产品名称">
            <el-input
              v-model="editForm.name"
              placeholder="请输入产品名称"
            ></el-input>
          </el-form-item>

          <el-form-item label="产品编码">
            <el-input
              v-model="editForm.package_code"
              placeholder="请输入产品编码"
            ></el-input>
          </el-form-item>

          <el-form-item label="积分">
            <el-input-number
              v-model="editForm.points"
              :min="1"
              :max="20"
              label="请输入积分"
            ></el-input-number>
          </el-form-item>

          <el-form-item label="产品图标">
            <el-upload
              style="margin-right: 30px"
              class="upload-demo"
              :action="uploadCoverImgUrl"
              :on-success="onSuccessFileCover"
              :on-remove="onRemoveFileCover"
              :data="{ type: '14' }"
              list-type="text"
            >
              <el-button size="small" type="primary">上传封面图</el-button>
            </el-upload>

            <div v-if="editForm.cover_img">
              <img
                :src="editForm.cover_img"
                alt=""
                style="width: 120px; height: 120px"
              />
            </div>
          </el-form-item>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="cancelDialogEdit">取 消</el-button>
        <el-button type="primary" @click="sureDialogEdit">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>
<script>
export default {
  props: ["editDetails"],
  data() {
    return {
      dialogVisibleEditInvite: false,
      editForm: {
        id: "",
        name: "",
        points: "",
        package_code: "",
        cover_img: "",
      },
      uploadCoverImgUrl: process.env.VUE_APP_BASE_API + "/app/uploadFiles",
    };
  },
  watch: {
    editDetails: {
      handler(newVal) {
        this.editForm = newVal;
      },
    },
  },
  methods: {
    // 确定
    sureDialogEdit() {
      if (this.editForm.name == "") {
        this.$message.error("请输入产品名称");
        return;
      } else {
        this.$emit("sureDialogEdit", this.editForm);
      }
    },

    // 取消
    cancelDialogEdit() {
      this.$emit("cancelDialogEdit", "");
    },

    // 上传主图
    onSuccessFileCover(val) {
      this.editForm.cover_img = val.data.path;
    },
    onRemoveFileCover() {
      this.editForm.cover_img = "";
    },
  },
};
</script>
<style scoped lang="scss"></style>
